
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>svg 之 viewBox · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../svg分组与复用/svg分组与复用.html" />
    
    
    <link rel="prev" href="../svg之fill及fill-rule/svg之fill及fill-rule.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../svg基础/svg基础.html">
            
                <a href="../svg基础/svg基础.html">
            
                    
                    svg 基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../svg基本图形/svg基本图形.html">
            
                <a href="../svg基本图形/svg基本图形.html">
            
                    
                    svg 基本图形
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../svg之path/svg之path.html">
            
                <a href="../svg之path/svg之path.html">
            
                    
                    svg 之 path
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../svg描边动画/svg描边动画.html">
            
                <a href="../svg描边动画/svg描边动画.html">
            
                    
                    svg 描边动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../svg之fill及fill-rule/svg之fill及fill-rule.html">
            
                <a href="../svg之fill及fill-rule/svg之fill及fill-rule.html">
            
                    
                    svg 之 fill 及 fill-rule
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7" data-path="svg之viewBox.html">
            
                <a href="svg之viewBox.html">
            
                    
                    svg 之 viewBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../svg分组与复用/svg分组与复用.html">
            
                <a href="../svg分组与复用/svg分组与复用.html">
            
                    
                    svg 分组与复用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../svg之marker/svg之marker.html">
            
                <a href="../svg之marker/svg之marker.html">
            
                    
                    svg 之 marker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../svg文本/svg文本.html">
            
                <a href="../svg文本/svg文本.html">
            
                    
                    svg 文本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../svg之pattern/svg之pattern.html">
            
                <a href="../svg之pattern/svg之pattern.html">
            
                    
                    svg 之 pattern
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../svg之clipPath和mask/svg之clipPath和mask.html">
            
                <a href="../svg之clipPath和mask/svg之clipPath和mask.html">
            
                    
                    svg 之 clipPath 和 mask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../svg之filter/svg之filter.html">
            
                <a href="../svg之filter/svg之filter.html">
            
                    
                    svg 之 filter
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >svg 之 viewBox</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x4E00;&#x4E2A;&#x6F14;&#x793A;&#x8BA9;&#x4F60;&#x8F7B;&#x677E;&#x4E86;&#x89E3;-svg-viewbox-&#x5982;&#x4F55;&#x5DE5;&#x4F5C;">&#x4E00;&#x4E2A;&#x6F14;&#x793A;&#x8BA9;&#x4F60;&#x8F7B;&#x677E;&#x4E86;&#x89E3; SVG viewBox &#x5982;&#x4F55;&#x5DE5;&#x4F5C;</h1>
<p><img src="imgs/demo.gif" alt="viewBox-demo"></p>
<p><a href="http://htmlpreview.github.io/?https://github.com/zhansingsong/fe-tutorials/blob/master/svg%E4%B9%8BviewBox/demo/viewBoxDemo.html" target="_blank">&#x1F3AF; &#x6F14;&#x793A;&#x5B9E;&#x4F8B;&#x5728;&#x7EBF;&#x5730;&#x5740;---&gt; &#x26F3;&#xFE0F;</a></p>
<h2 id="viewport">viewport</h2>
<p>SVG &#x5143;&#x7D20;&#x90FD;&#x6709;&#x4E2A; viewport&#xFF0C;&#x5373;&#x89C6;&#x56FE;&#x7A97;&#x53E3;&#x3002;viewport &#x7684;&#x5927;&#x5C0F;&#x7531; SVG &#x5143;&#x7D20;&#x7684;&#x5927;&#x5C0F;&#x51B3;&#x5B9A;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- &#x9ED8;&#x8BA4;&#x5355;&#x4F4D; px --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">svg</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;200&quot;</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- &#x5176;&#x5B83; svg &#x5143;&#x7D20; --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
</code></pre>
<p>&#x5982;&#x4E0A; SVG &#x5143;&#x7D20;&#x7684; viewport &#x4E3A; <code>200 * 200</code>&#x3002;</p>
<h2 id="viewboxmin-x-min-y-width-height">viewBox(min-x, min-y, width, height)</h2>
<p><strong>&#x89C6;&#x76D2;</strong>&#xFF0C;&#x5373; SVG &#x7684;&#x53EF;&#x89C6;&#x8303;&#x56F4;&#x3002;&#x5F53;&#x4E0D;&#x8BBE;&#x5B9A; <code>viewBox</code> &#x65F6;&#xFF0C;<code>viewBox</code> &#x7B49;&#x4E8E; <code>viewport</code>&#x3002; &#x5F53;&#x8BBE;&#x5B9A;&#x5730; <code>viewBox</code> &#x65F6;&#xFF0C;SVG &#x4F1A;&#x628A; <code>viewBox</code> &#x8BBE;&#x5B9A;&#x533A;&#x57DF;&#x7F29;&#x653E;&#x5230; <code>viewport</code> &#x7684;&#x5927;&#x5C0F;&#x3002;&#x5373; <code>viewBox</code>&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x63A7;&#x5236; SVG &#x5185;&#x5BB9;&#x5982;&#x4F55;&#x663E;&#x793A;&#x3002;&#x4E0D;&#x662F;&#x5F88;&#x597D;&#x7406;&#x89E3;&#xFF0C;&#x6765;&#x4E2A;&#x6F14;&#x793A;&#xFF1A;</p>
<p><img src="imgs/vb.gif" alt="viewBox"></p>
<p>&#x1F334; <a href="http://htmlpreview.github.io/?https://github.com/zhansingsong/fe-tutorials/blob/master/svg%E4%B9%8BviewBox/demo/vb.html" target="_blank">&#x6F14;&#x793A;&#x5B9E;&#x4F8B;&#x5728;&#x7EBF;&#x5730;&#x5740;</a> &#x1F334;</p>
<p>&#x4E0A;&#x8FF0;&#x6F14;&#x793A;&#x5B9E;&#x4F8B; <code>viewBox</code> &#x7684;&#x5BBD;&#x9AD8;&#x6BD4;&#x521A;&#x597D;&#x4E0E; <code>viewport</code> &#x7684;&#x4E00;&#x81F4;&#x3002;&#x5982;&#x679C;&#x6BD4;&#x4F8B;&#x4E0D;&#x4E00;&#x81F4;&#x4F1A;&#x600E;&#x6837;&#x5462;&#xFF1F;</p>
<h2 id="preserveaspectratioalign-meetorslice">preserveAspectRatio(align, meetOrSlice)</h2>
<p>&#x5728;&#x6BD4;&#x4F8B;&#x4E0D;&#x4E00;&#x81F4;&#x7684;&#x60C5;&#x51B5;&#x9700;&#x8981;&#x89E3;&#x51B3;&#x4E24;&#x4E2A;&#x95EE;&#x9898;&#xFF1A;</p>
<ul>
<li><code>viewBox</code> &#x5982;&#x4F55;&#x4E0E; <code>viewport</code> &#x5BF9;&#x9F50;</li>
<li><code>viewBox</code> &#x5982;&#x4F55;&#x7F29;&#x653E;</li>
</ul>
<p>&#x8981;&#x89E3;&#x51B3;&#x4E0A;&#x8FF0;&#x7684;&#x4E24;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x4E0E; <code>viewBox</code> &#x5BC6;&#x5207;&#x76F8;&#x5173;&#x7684;&#x5C5E;&#x6027; <code>preserveAspectRatio</code>&#xFF0C;&#x7528;&#x4E8E;&#x63A7;&#x5236; <code>viewBox</code> &#x5982;&#x4F55;&#x5BF9;&#x9F50;&#x53CA;&#x7F29;&#x653E;&#x3002;&#x5E76;&#x4E14; <code>preserveAspectRatio</code> &#x80FD;&#x7EF4;&#x6301; <code>viewBox</code> &#x5BBD;&#x9AD8;&#x6BD4;&#x3002;&#x5982;&#x679C; <code>preserveAspectRatio: none</code> &#x5219; <code>viewBox</code> &#x4F1A;&#x88AB;&#x5F3A;&#x5236;&#x4EE5;<code>viewport</code> &#x7684;&#x5BBD;&#x9AD8;&#x6BD4;&#x8FDB;&#x884C;&#x7F29;&#x653E;&#x3002;</p>
<h3 id="align">align</h3>
<p>&#x8981;&#x89E3;&#x51B3; <code>viewBox</code> &#x5982;&#x4F55;&#x4E0E; <code>viewport</code> &#x5BF9;&#x9F50;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8BBE;&#x7F6E; <code>preserveAspectRatio</code> &#x7684; <code>align</code> &#x503C;&#x8FDB;&#x884C;&#x63A7;&#x5236;&#x3002;
<code>preserveAspectRatio</code> &#x63D0;&#x4F9B;&#x4E86;&#x7684; 9 &#x79CD;&#x5BF9;&#x9F50;&#x65B9;&#x5F0F;&#xFF1A;</p>
<ul>
<li>xMinYMin</li>
<li>xMidYMin</li>
<li>xMaxYMin</li>
<li>xMinYMid</li>
<li>xMidYMid</li>
<li>xMaxYMid</li>
<li>xMinYMax</li>
<li>xMidYMax</li>
<li>xMaxYMax</li>
</ul>
<p><img src="imgs/align.png" alt="align"></p>
<p><strong>&#x5982;&#x4F55;&#x5DE5;&#x4F5C;&#xFF1F;</strong></p>
<p>&#x5047;&#x5982;&#x4E00; SVG &#x5143;&#x7D20;&#x7684; <code>viewport</code> &#x5927;&#x5C0F;&#x4E3A; <code>600*600</code>&#x3001; <code>viewBox: 0 0 200 200</code>&#x3001;<code>preserveAspectRatio: xMaxYMax meet</code>&#x3002;</p>
<ul>
<li>&#x627E;&#x5230; <code>viewport</code> &#x7684; <code>xMaxYMax</code> &#x5750;&#x6807;&#x70B9; <code>(600, 600)</code></li>
<li>&#x627E;&#x5230; <code>viewBox</code> &#x7684; <code>xMaxYMax</code> &#x5750;&#x6807;&#x70B9; <code>(200, 200)</code></li>
<li><code>viewport</code> &#x7684; <code>(600, 600)</code> &#x5750;&#x6807;&#x70B9;&#x4E0E; <code>viewBox</code> &#x7684;&#x5750;&#x6807;&#x70B9; <code>(200, 200)</code> &#x5BF9;&#x9F50;</li>
</ul>
<p><img src="imgs/align1.png" alt=""></p>
<h3 id="meetorslice">meetOrSlice</h3>
<p>&#x5BF9;&#x9F50;&#x95EE;&#x9898;&#x89E3;&#x51B3;&#x4E86;&#xFF0C;&#x5269;&#x4E0B;&#x5C31;&#x89E3;&#x51B3;&#x7F29;&#x653E;&#x95EE;&#x9898;&#x3002;&#x8981;&#x89E3;&#x51B3; <code>viewBox</code> &#x7F29;&#x653E;&#x3002;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8BBE;&#x7F6E; <code>preserveAspectRatio</code> &#x7684; <code>meetOrSlice</code> &#x503C;&#x8FDB;&#x884C;&#x63A7;&#x5236;&#x3002;</p>
<ul>
<li><p>meet: &#x4FDD;&#x6301; <code>viewBox</code> &#x7684;&#x5BBD;&#x9AD8;&#x6BD4;&#xFF0C;&#x540C;&#x65F6;&#x8BA9;&#x6574;&#x4E2A; <code>viewBox</code> &#x521A;&#x597D;&#x5728; <code>viewport</code> &#x5185;&#x3002;&#x7B80;&#x5355;&#x8BF4;&#x5C31;&#x662F;&#xFF1A;&#x4EE5;&#x5927;&#x6BD4;&#x4F8B;&#x4E3A;&#x51C6;&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E; <code>background-size: contain</code>&#x3002; </p>
<p>&#x5047;&#x5982;&#x4E00; SVG &#x5143;&#x7D20;&#x7684; <code>viewport</code> &#x5927;&#x5C0F;&#x4E3A; <code>600*600</code>&#x3001; <code>viewBox: 0 0 200 100</code>&#x3001;<code>preserveAspectRatio: xMidYMid meet</code>&#x3002;&#x6B64;&#x65F6; <code>viewBox</code> &#x4E0E; <code>viewport</code> &#x5BBD;&#x6BD4;&#x4F8B;&#x4E3A; <code>200 / 600</code>&#xFF0C;&#x800C;&#x9AD8;&#x6BD4;&#x4F8B;&#x4E3A; <code>100 / 600</code>&#xFF0C;&#x6240;&#x4EE5;&#x5C31;&#x4EE5;&#x5BBD;&#x6BD4;&#x4F8B;&#x4E3A;&#x51C6;&#x8FDB;&#x884C;&#x7F29;&#x653E;&#xFF0C;&#x653E;&#x5927;&#x5230;&#x4E0E; <code>viewport</code> &#x7684;&#x5BBD;&#x4E00;&#x6837;&#x3002;</p>
<p><img src="imgs/meet.png" alt="meet"></p>
</li>
<li><p>slice&#xFF1A;&#x4FDD;&#x6301; <code>viewBox</code> &#x7684;&#x5BBD;&#x9AD8;&#x6BD4;&#xFF0C;&#x540C;&#x65F6;&#x8BA9;&#x6574;&#x4E2A; <code>viewport</code> &#x521A;&#x597D;&#x88AB; <code>viewBox</code> &#x8986;&#x76D6;&#x3002;&#x7B80;&#x5355;&#x8BF4;&#x5C31;&#x662F;&#xFF1A;&#x4EE5;&#x5C0F;&#x6BD4;&#x4F8B;&#x4E3A;&#x51C6;&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E;  <code>background-size: cover</code></p>
<p>&#x5047;&#x5982;&#x4E00; SVG &#x5143;&#x7D20;&#x7684; <code>viewport</code> &#x5927;&#x5C0F;&#x4E3A; <code>600*600</code>&#x3001; <code>viewBox: 0 0 200 100</code>&#x3001;<code>preserveAspectRatio: xMidYMid meet</code>&#x3002;&#x6B64;&#x65F6; <code>viewBox</code> &#x4E0E; <code>viewport</code> &#x5BBD;&#x6BD4;&#x4F8B;&#x4E3A; <code>200 / 600</code>&#xFF0C;&#x800C;&#x9AD8;&#x6BD4;&#x4F8B;&#x4E3A; <code>100 / 600</code>&#xFF0C;&#x6240;&#x4EE5;&#x5C31;&#x4EE5;&#x9AD8;&#x6BD4;&#x4F8B;&#x4E3A;&#x51C6;&#x8FDB;&#x884C;&#x7F29;&#x653E;&#xFF0C;&#x653E;&#x5927;&#x5230;&#x4E0E; <code>viewport</code> &#x7684;&#x9AD8;&#x4E00;&#x6837;&#x3002;</p>
<p><img src="imgs/slice.png" alt="slice"></p>
</li>
</ul>
<h2 id="&#x603B;&#x7ED3;">&#x603B;&#x7ED3;</h2>
<p>  &#x672C;&#x6587;&#x901A;&#x8FC7;&#x4E00;&#x4E2A;&#x6F14;&#x793A;&#x5B9E;&#x4F8B;&#x7ED9;&#x5927;&#x5BB6;&#x5C55;&#x793A;&#x4E86; SVG viewBox &#x5982;&#x4F55;&#x5DE5;&#x4F5C;&#x3002;&#x53EF;&#x4EE5;&#x8BA9;&#x8BFB;&#x8005;&#x4EE5;&#x4E00;&#x79CD;&#x6700;&#x8F7B;&#x677E;&#x7684;&#x65B9;&#x5F0F;&#x53BB;&#x4E86;&#x89E3; viewBox &#x5DE5;&#x4F5C;&#x673A;&#x5236;&#xFF0C;&#x66F4;&#x597D;&#x5730;&#x638C;&#x63E1; viewBox&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../svg之fill及fill-rule/svg之fill及fill-rule.html" class="navigation navigation-prev " aria-label="Previous page: svg 之 fill 及 fill-rule">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../svg分组与复用/svg分组与复用.html" class="navigation navigation-next " aria-label="Next page: svg 分组与复用">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"svg 之 viewBox","level":"1.7","depth":1,"next":{"title":"svg 分组与复用","level":"1.8","depth":1,"path":"svg分组与复用/svg分组与复用.md","ref":"./svg分组与复用/svg分组与复用.md","articles":[]},"previous":{"title":"svg 之 fill 及 fill-rule","level":"1.6","depth":1,"path":"svg之fill及fill-rule/svg之fill及fill-rule.md","ref":"./svg之fill及fill-rule/svg之fill及fill-rule.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"svg之viewBox/svg之viewBox.md","mtime":"2019-09-19T11:41:49.412Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-10-21T06:03:10.264Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

